﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:themes="clr-namespace:CmdletHelpEditor.Themes"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:controls="clr-namespace:CmdletHelpEditor.Controls"
                    xmlns:themes1="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
	<ResourceDictionary.MergedDictionaries>
		<ResourceDictionary Source="ClosableTabItem.xaml"/>
		<ResourceDictionary Source="Colors.xaml"/>
		<ResourceDictionary Source="MenuItem.xaml"/>
	</ResourceDictionary.MergedDictionaries>
	<Color x:Key="TabPanelBackgroundColorBase">Transparent</Color>
	<Color x:Key="LineButtonBackgroundColorBright">LightGoldenrodYellow</Color>
	<Color x:Key="LineButtonBackgroundColorDark">#FAEEB1</Color>
	<Color x:Key="LineButtonBackgroundColorDisabledBright">#EEE</Color>
	<Color x:Key="LineButtonBackgroundColorDisabledDark">#999</Color>
	<SolidColorBrush x:Key="LineButtonBorderBrush" Color="#FF8693BD"/>
	<SolidColorBrush x:Key="TabControl_BackgroundBrush_Base" Color="{StaticResource TabControlBackgroundColorBase}"/>
	<SolidColorBrush x:Key="TabPage_InnerBorderBrushDark" Color="#FF8DB2E3"/>
	<!-- The color to be used when drawing the arrows on the scrollbar's line-buttons -->
	<SolidColorBrush x:Key="LineButtonBrush" Color="#FF14273D"/>
	<!-- Brushes used for styling the TabControl -->
	<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" x:Key="LineButtonBackgroundBrush">
		<GradientStop Offset="0.3" Color="{StaticResource LineButtonBackgroundColorBright}"/>
		<GradientStop Offset="0.4" Color="{StaticResource LineButtonBackgroundColorDark}"/>
		<GradientStop Offset="1" Color="{StaticResource LineButtonBackgroundColorBright}"/>
	</LinearGradientBrush>
	<LinearGradientBrush x:Key="LineButtonHoverBrush" StartPoint="0.5,0" EndPoint="0.5,1">
		<GradientStop Color="#FFFFD5A0" Offset="0.3"/>
		<GradientStop Color="#FFFFA335" Offset="0.51"/>
		<GradientStop Color="#FFFFC14A" Offset="0.986"/>
	</LinearGradientBrush>
	<!-- The color for the scrollbar's line-buttons when they're clicked/pressed -->
	<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" x:Key="LineButtonPressedBrush">
		<GradientStop Offset="0" Color="{StaticResource LineButtonBackgroundColorBright}"/>
		<GradientStop Offset="0.6" Color="{StaticResource LineButtonBackgroundColorDark}"/>
		<GradientStop Offset="0.7" Color="{StaticResource LineButtonBackgroundColorBright}"/>
	</LinearGradientBrush>
	<LinearGradientBrush x:Key="TabPanelBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
		<LinearGradientBrush.GradientStops>
			<GradientStop Offset="0.98" Color="{StaticResource TabPanelBackgroundColorBase}"/>
			<GradientStop Offset="0.99" Color="{StaticResource BorderColorBase}"/>
		</LinearGradientBrush.GradientStops>
	</LinearGradientBrush>
	<!-- The color to be used for painting the interior of the TabItem-menu's path -->
	<LinearGradientBrush x:Key="TabMenuButtonBrush" StartPoint="0,0" EndPoint="1,1">
		<GradientStop Offset="0" Color="White"/>
		<GradientStop Offset="1" Color="#F3F3E3"/>
	</LinearGradientBrush>
	<!-- The color for the scrollbar's line-buttons when they're disabled -->
	<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" x:Key="LineButtonDisabledBrush">
		<GradientStop Offset="0" Color="{StaticResource LineButtonBackgroundColorDisabledBright}"/>
		<GradientStop Offset="1" Color="{StaticResource LineButtonBackgroundColorDisabledDark}"/>
	</LinearGradientBrush>

	<!-- The background color of the TabItems popup-menu -->
	<LinearGradientBrush x:Key="TabItemMenuBackcolor" StartPoint="0,0" EndPoint="1,1">
		<GradientStop Offset="0" Color="White"/>
		<GradientStop Offset="1" Color="#EEE"/>
	</LinearGradientBrush>

	<Geometry x:Key="ArrowLeft">M0,5 L10,10 10,0Z</Geometry>
	<Geometry x:Key="ArrowRight">M0,0 L10,5 L0,10Z</Geometry>
	<Geometry x:Key="TabMenuButton">M0,1 H0,5 M7,8 L0,8 0,2 10,2 L10,5 M10,8 L10,10 8,10Z</Geometry>
	
	<Thickness x:Key="TabPanelPadding">4,0,4,0</Thickness>
	<Thickness x:Key="TabPanelScrollControlsPanelMargin">5,0,0,2</Thickness>
	<Path x:Key="ArrowLeftPath"
            Margin="4,3"
            Data="{StaticResource ArrowLeft}"
            Stroke="{StaticResource LineButtonBrush}" 
            Fill="{StaticResource LineButtonBrush}"
            Stretch="Fill"
            VerticalAlignment="Center"
            HorizontalAlignment="Center"/>
	<Path x:Key="ArrowRightPath"
            Margin="4,3"
            Data="{StaticResource ArrowRight}"
            Stroke="{StaticResource LineButtonBrush}" 
            Fill="{StaticResource LineButtonBrush}"
            Stretch="Fill"
            VerticalAlignment="Center"
            HorizontalAlignment="Center"/>
	<Path x:Key="TabMenuButtonPath"
            Margin="2"
            Data="{StaticResource TabMenuButton}"
            Stroke="{StaticResource LineButtonBrush}" 
            Fill="{StaticResource TabMenuButtonBrush}"
            Stretch="Fill"
            VerticalAlignment="Center"
            HorizontalAlignment="Center"/>
	<system:Double x:Key="ButtonWidthAndHeight">16</system:Double>
	<Style x:Key="LineButtonStyle" TargetType="{x:Type RepeatButton}">
		<Setter Property="Focusable" Value="False"/>
		<Setter Property="Height" Value="{StaticResource ButtonWidthAndHeight}"/>
		<Setter Property="Width" Value="{StaticResource ButtonWidthAndHeight}"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type RepeatButton}">
					<Border Name="ButtonBorder" Margin="1"
                          BorderBrush="{StaticResource LineButtonBorderBrush}" 
                          Background="{StaticResource LineButtonBackgroundBrush}" 
                          CornerRadius="1" 
                          BorderThickness="1">
						<ContentPresenter HorizontalAlignment="Stretch"
                                       VerticalAlignment="Stretch"/>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsMouseOver" Value="true">
							<Setter TargetName="ButtonBorder" Property="Background" 
                                Value="{StaticResource LineButtonHoverBrush}" />
						</Trigger>
						<Trigger Property="IsPressed" Value="true">
							<Setter TargetName="ButtonBorder" Property="Background" 
                                Value="{StaticResource LineButtonPressedBrush}" />
						</Trigger>
						<Trigger Property="IsEnabled" Value="False">
							<Setter TargetName="ButtonBorder" Property="Background" 
                                Value="{StaticResource LineButtonDisabledBrush}" />
							<Setter TargetName="ButtonBorder" Property="Opacity" 
                                Value="0.4"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="TabMenuButtonStyle" TargetType="{x:Type MenuItem}">
		<Setter Property="Focusable" Value="False"/>
		<Setter Property="Height" Value="{StaticResource ButtonWidthAndHeight}"/>
		<Setter Property="Width" Value="{StaticResource ButtonWidthAndHeight}"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type MenuItem}">
					<Border Name="ButtonBorder"
							Margin="1"
							BorderBrush="{StaticResource LineButtonBorderBrush}"
							Background="{StaticResource LineButtonBackgroundBrush}"
							CornerRadius="1"
							BorderThickness="1">
						<Grid>
							<ContentPresenter ContentSource="Header"
											  Content="{StaticResource TabMenuButtonPath}"
											  HorizontalAlignment="Stretch"
											  VerticalAlignment="Stretch"/>
							<Popup Name="Popup"
								   Placement="Bottom"
								   IsOpen="{TemplateBinding IsSubmenuOpen}"
								   AllowsTransparency="True"
								   Focusable="False"
								   PopupAnimation="Fade">
								<!-- 
                              Since we override the ControlTemplate, we're also responsible
                              for drawing stuff like the shadow around the popup-menu.
                              
                              Here, I'll use a Chrome that's provided in the Aero assembly. 
                              Note that, in order to use this (that is, the namespace defined
                              at the very top of this window), a reference to 
                              PresentationFramework.Aero is required.
                           -->
								<themes1:SystemDropShadowChrome Color="#71000000"
																CornerRadius="1"
																Margin="0,0,8,8"
																SnapsToDevicePixels="True">
									<Border Name="SubmenuBorder"
											Margin="1"
											SnapsToDevicePixels="True"
											BorderBrush="{StaticResource LineButtonBorderBrush}"
											Background="{StaticResource TabItemMenuBackcolor}"
											CornerRadius="1"
											BorderThickness="1">
										<StackPanel IsItemsHost="True"
													KeyboardNavigation.DirectionalNavigation="Cycle" />
									</Border>
								</themes1:SystemDropShadowChrome>
							</Popup>
						</Grid>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsHighlighted" Value="true">
							<Setter TargetName="ButtonBorder" Property="Background" Value="{StaticResource LineButtonHoverBrush}" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="TabMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
		<Setter Property="Header" Value="{Binding Path=Header}" />
		<Setter Property="IsEnabled" Value="{Binding Path=IsEnabled}" />
		<!-- 
            By making the MenuItems checkable AND binding the IsChecked
            property to the IsSelected property of the TabItems, we'll 
            efficiently allow to pick the selected TabItem from the Menu
            with a simple two-way binding.
         -->
		<Setter Property="IsCheckable" Value="{Binding Path=IsEnabled}" />
		<Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
		<!--<Setter Property="Foreground" Value="{StaticResource MenuItemForegroundBrush}"/>-->
		<!--<Style.Triggers>
			<Trigger Property="IsHighlighted" Value="True">
				<Setter Property="Foreground"
                       Value="{StaticResource TabItem_TextBrush_Selected}"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter Property="Foreground" 
                       Value="{StaticResource MenuItem_DisabledForegroundBrush}"/>
				<Setter Property="Background"
                                Value="{StaticResource MenuItem_DisabledBackgroundBrush}"/>
			</Trigger>
			--><!-- Provide a hover-appearance for disabled MenuItems -->
			<!-- 
               This won't work due to the fact that disabled items neither receive
               IsHighlighted nor IsMouseOver ... I'll leave this for now. 
            <MultiTrigger>
               <MultiTrigger.Conditions>
                  <Condition SourceName="Border" Property="IsMouseOver" Value="True"/>
                  <Condition Property="IsEnabled" Value="False"/>
               </MultiTrigger.Conditions>
               <Setter Property="Background"
                                Value="{StaticResource MenuItem_DisabledBackgroundBrush}"/>
            </MultiTrigger>
            --><!--
		</Style.Triggers>-->
	</Style>
	<Style TargetType="{x:Type controls:ClosableTabControl}" x:Key="ScrollableTabControl">
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="BorderThickness" Value="1,0,1,1"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="TabControl">
					<Grid KeyboardNavigation.TabNavigation="Local">
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto"/>
							<RowDefinition Height="*"/>
						</Grid.RowDefinitions>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="25"/>
							<ColumnDefinition Width="*"/>
						</Grid.ColumnDefinitions>
						<!--
                        In order to still draw the LinearGradient that makes up for the bottom
                        line of the TabPanel, we need to wrap the ScrollViewer in a Border 
                        control that will be responsible for drawing the background.
                     -->
						<Button Grid.Row="0"
								Grid.Column="0"
								Content="+"
								Command="{Binding Path=AddTabCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:ClosableTabControl}}}"/>
						<Border Grid.Row="0"
								Grid.Column="1"
								Name="TabPanelBorder"
								Height="25"
								Background="{StaticResource TabPanelBackgroundBrush}">
							<Grid>
								<Grid.ColumnDefinitions>
									<!-- The TabItems (resp. the TabPanel) will appear here -->
									<ColumnDefinition Width="*"/>
									<!-- The ScrollViewer controls will appear here -->
									<ColumnDefinition Width="Auto"/>
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition Height="*"/>
									<RowDefinition Height="Auto"/>
								</Grid.RowDefinitions>
								<ScrollViewer Grid.Row="0" Grid.RowSpan="2"
                                         VerticalScrollBarVisibility="Disabled"
                                         CanContentScroll="True" 
                                         HorizontalScrollBarVisibility="Hidden"
                                         IsDeferredScrollingEnabled="False"
                                         SnapsToDevicePixels="True"
                                         Name="svTP"
                                         HorizontalAlignment="Stretch" 
                                         VerticalAlignment="Stretch"
                                         >
									<!--
                                    This is the area in which TabItems (the strips) will be drawn.

                                    Unselected TabItems will apply a right margin of -4px in 
                                    order to overlay the item to their right. In order to allow 
                                    the rightmost TabItem to be fully displayed (rather than
                                    being overlayed with the Button-Panel), we need to apply this
                                    as the Margin here.
                                 -->
									<themes:ScrollableTabPanel IsItemsHost="True"
															   x:Name="PART_ScrollContentPresenter"
															   Margin="{StaticResource TabPanelPadding}"
															   RightOverflowMargin="4"
															   AnimationTimeSpan="0:0:0.25"
															   LineScrollPixelCount="100"
															   KeyboardNavigation.TabIndex="1"/>
								</ScrollViewer>
								<StackPanel Grid.Row="1"
											Grid.Column="1"
											Orientation="Horizontal"
											Margin="{StaticResource TabPanelScrollControlsPanelMargin}">
									<!-- 
                                 The two RepeatButtons below will actually provide the scroll-
                                 functionality for the TabItems. Since the ScrollableTabPanel
                                 does not implements PageLeft/PageRight, LineLeft/LineRight
                                 are used.
                              -->
									<RepeatButton x:Name="cmdScrollLeft"
												  Style="{StaticResource LineButtonStyle}"
												  CommandTarget="{Binding ElementName=svTP}"
												  Command="ScrollBar.LineLeftCommand"
												  Content="{StaticResource ArrowLeftPath}"
												  IsEnabled="{Binding ElementName=PART_ScrollContentPresenter, Path=CanScrollLeft}"/>
									<RepeatButton x:Name="cmdScrollRight"
												  Style="{StaticResource LineButtonStyle}"
												  CommandTarget="{Binding ElementName=svTP}"
												  Command="ScrollBar.LineRightCommand"
												  Content="{StaticResource ArrowRightPath}"
												  IsEnabled="{Binding ElementName=PART_ScrollContentPresenter, Path=CanScrollRight}"/>
									<!-- 
                                 This will present another "button" which will open up the Menu
                                 containing all TabItems, with the selected one being checked.
                                 Clicking an item here will select the respective TabItem.
                              -->
									<Menu Background="Transparent">
									<!--<Menu Background="Transparent">-->
										<MenuItem ItemContainerStyle="{StaticResource TabMenuItem}"
												  ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                AncestorType={x:Type controls:ClosableTabControl}}, Path=Items}"
												  Style="{StaticResource TabMenuButtonStyle}">
										</MenuItem>
										<!--<MenuItem Style="{StaticResource TabMenuButtonStyle}"
                                           ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                AncestorType={x:Type TabControl}}, Path=Items}"
                                           ItemContainerStyle="{StaticResource TabMenuItem}">
										</MenuItem>-->
									</Menu>
								</StackPanel>
							</Grid>
						</Border>

						<!-- 
                        This is the outer border of the TabControl itself, actually meaning
                        the Panel that will host a TabItem's content.
                        The top-border here will not be drawn as, otherwise, the TabPanel
                        would always show a thin line for the selected Tab (which we want 
                        to avoid).
                     -->
						<Border Grid.ColumnSpan="2"
								Grid.Column="0"
								BorderThickness="1,0,1,1"
								Grid.Row="1"
								BorderBrush="{StaticResource TabItemBorderBrushSelected}"
								Background="{StaticResource TabControl_BackgroundBrush_Base}">
							<ContentPresenter x:Name="PART_SelectedContentHost"
											  ContentSource="SelectedContent"
											  Margin="0"/>
						</Border>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>